package com.mak001.lite.multiSkill.subs;

import org.rsbuddy.tabs.Equipment;
import org.rsbuddy.tabs.Inventory;
import org.rsbuddy.widgets.Bank;

import com.mak001.lite.multiSkill.MainLite;
import com.mak001.lite.multiSkill.Methods;
import extras.mak001.Time;
import com.mak001.lite.multiSkill.subScript;
import com.rsbuddy.event.events.MessageEvent;
import com.rsbuddy.script.methods.Game;
import com.rsbuddy.script.methods.Widgets;
import com.rsbuddy.script.util.Timer;
import com.rsbuddy.script.wrappers.Component;

public class AlcherLite extends subScript {
	int fireRune = 554;
	int natureRune = 561;
	int staff = 1387;
	int item;
	int alchs;

	boolean high = false;

	@Override
	public void execute() {
		if (Inventory.contains(item)) {
			if (!Equipment.containsOneOf(staff)) {
				if (Inventory.getCount(natureRune) == 1) {
					if (high == true) {
						if (Inventory.getCount(fireRune) < 5) {
							Methods.stopSub();
						}
					} else {
						if (Inventory.getCount(fireRune) < 3) {
							Methods.stopSub();
						}
					}
				}
			} else if (Inventory.getCount(natureRune) == 0) {
				Methods.stopSub();
			}
			if (Game.getCurrentTab() != Game.TAB_MAGIC) {
				Game.openTab(Game.TAB_MAGIC);
			}
			Component c = Widgets.getComponent(192, high ? 59 : 38);
			if (c != null) {
				for (int i = 0; i < 5; i++) {
					Timer to = new Timer(3000);
					c.click();
					while (to.isRunning()
							&& Game.getCurrentTab() != Game.TAB_INVENTORY) {
						MainLite.sleep(100);
					}
					if (Game.getCurrentTab() == Game.TAB_INVENTORY) {
						if (Inventory.getItem(item) != null) {
							if (Inventory.getItem(item).click(true)) {
								alchs++;
								MainLite.sleep(5000);
							}
						}
					}
				}
			}
		} else {
			if (!Bank.isOpen()) {
				Bank.open();
			} else {
				if (Bank.getCount(item) > 0) {
					Bank.withdraw(item, 26);
				} else {
					Methods.stopSub();
				}
			}
		}
	}

	@Override
	public int[] required() {
		int[] req;
		if (Equipment.containsOneOf(staff)) {
			int[] a = { natureRune };
			req = a;
		} else {
			int[] b = { fireRune, natureRune };
			req = b;
		}
		return req;
	}

	public void setItem(String s) {
		try {
			item = Integer.parseInt(s);
		} catch (NumberFormatException e) {
			Methods.stopSub();
		}
	}

	@Override
	public boolean canSwitch() {
		return true;
	}

	@Override
	public String getStatus() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int skill() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void messageRecieved(MessageEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public String[] paintString() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Time getTime() {
		// TODO Auto-generated method stub
		return null;
	}

}
